/**
 * 轻提示方法
 * */
const utils = {
  toast(title = '...加载失败') {
    wx.showToast({
      title,
      mask: true,
      icon: 'none',
    })
  },
  //获取当前页面
  getCurrentPage() {
    const pagesList = getCurrentPages()
    const currentPagePath = pagesList[pagesList.length - 1].route
    return currentPagePath
  },
  //判断页面是不是tabBar页面
  pageIsTabBar(url){
    // eslint-disable-next-line no-undef
    const appConfigList = __wxConfig.tabBar.list
    return appConfigList.some(({ pagePath }) => {
      return pagePath.startsWith(url)
    })
  },
  //跳转到登录页
  skipLogin(){
   const pagePath = utils.getCurrentPage()
   const skipType = utils.pageIsTabBar(pagePath)  ? 'switchTab' : 'redirectTo'
   wx.redirectTo({
    url: `/pages/login/index?returnUrl=/${pagePath}&returnType=${skipType}`,
  })
  }
}
export default utils

wx.utils = utils
